﻿// ===============================================================================
// XCI.NET 西安交通信息WinForm开发框架 2018 版权所有
// ===============================================================================
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraTreeList.Columns;
using XCI.Data.Entity;
using XCI.Helper;
using XCI.Windows.Controls;

namespace XCI.Windows.Plugin.GridSetting.UI
{
    [ToolboxItem(false)]
    public partial class TreeColumns : BaseGridColumns
    {
        public TreeColumns()
        {
            InitializeComponent();
        }

        private TreeSettingPlugin Plugin { get; set; }

        public void Initialize(TreeSettingPlugin uiplugin)
        {
            this.Plugin = uiplugin;
            base.MainGrid.MenuManager = Plugin.Tree.MenuManager;
            Initialize();
        }

        protected override IList GetColumns()
        {
            List<object> list = new List<object>();
            foreach (var item in Plugin.Tree.Columns)
            {
                list.Add(item);
            }
            return list;
        }

        protected override void NewColumn()
        {
            var col = new TreeListColumn();
            col.Name = $"tcol_{StringHelper.Guid()}";
            col.Visible = true;
            col.OptionsColumn.AllowEdit = false;
            Plugin.Tree.Columns.Add(col);
            MainGrid.DataSource = GetColumns();
            MainGrid.RefreshDataSource();
            MainView.MoveLastVisible();
        }

        protected override void RemoveColumn(object col)
        {
            Plugin.Tree.Columns.Remove((TreeListColumn)col);
            MainGrid.DataSource = GetColumns();
            MainGrid.RefreshDataSource();
        }

        protected override void AutoBuildColumn()
        {
            Plugin.AutoBuildColumn();
            MainGrid.RefreshDataSource();
        }

        protected override EntityData GetMetadata()
        {
            return Plugin.Metadata;
        }
    }
}
